package com.csu.petstore.pojo;

import com.csu.petstore.pojo.CartItem;
import lombok.Data;

import java.math.BigDecimal;
import java.util.*;

@Data
public class Cart {

    private String userId;
    private final Map<String, CartItem> itemMap = Collections.synchronizedMap(new HashMap<String, CartItem>());
    private List<CartItem> itemList = new ArrayList<CartItem>();
    private BigDecimal subTotal;

    public BigDecimal getSubTotal() {

        BigDecimal subTotal = new BigDecimal("0");

        for (int i = 0 ; i < itemList.size() ; i++){
            BigDecimal listPrice = itemList.get(i).getListPrice();
            BigDecimal quantity = new BigDecimal(String.valueOf(itemList.get(i).getQuantity()));
            subTotal = subTotal.add(listPrice.multiply(quantity));
        }
        return subTotal;
    }



}
